#include"process.h"

#define LENGTH 101
#define LABLE '#'
void FlushProcess(double size , double current_size)
{
    double rate = (current_size/size)*100.0;
    char bar[LENGTH];
    memset(bar, '\0', sizeof(bar));

    char* symb = "/-|\\";
    size_t len = strlen(symb);
    static int index = 0;

    int cnt = (int)rate;//打印多少个'#' 有进度的整数部分决定
    for(int i = 0;i<cnt;i++) bar[i] = '#';
    printf("[%-100s][%.1lf%%][%c]\r" , bar ,rate, symb[index++] );
    fflush(stdout);//记得手动刷新
    index%=len;
    usleep(40000);
    if(current_size >= size) printf("\n");//最后一次换行
}
void Process()
{
    //[#######][x%][|]
    int cnt = 0;
    char bar[LENGTH];
    char * symb = "/-|\\";
    size_t len = strlen(symb);

    //初始化
    memset(bar, '\0' , sizeof(bar));
    while(cnt < 100)
    {
        bar[cnt++]=LABLE;
        printf("[%-100s][%d%%][%c]\r" , bar , cnt , symb[cnt%len]);
        fflush(stdout);
        usleep(10000);
    }
    printf("\n");

}
